<?php
class Index extends CI_Controller {
	function __construct() {
		parent::__construct ();
        #Load lang
		$this->load->helper('url');
		$this->lang->load('admin/common');
		$this->lang->load('admin/defaults');
		$this->lang->load('admin/login');
        #Load Model
		$this->load->model('User_model');
        #Load Library
		$this->load->library('hash');
		$this->session->sess_destroy();//Huy session
	}

  public function index()
	{
	    
		// $salt = $this->hash->key(8);
        // $password_user = $this->hash->create($this->input->post('password_user'), $salt, 'md5sha512');
		$k= $this->input->post('pass');
		//load session library
        if(!$this->session) $this->load->library('session');
		
		$ssid=session_id();
    	$id='notok';
    	$user='notFound ';
    	$pass='notFound';
    	if(isset($_POST["id"]))
    		$id=$_POST['id'];
    	if(isset($_POST["user"]))
    		$user=$this->filter->injection_html($this->input->post('user'));;
    	if(isset($_POST["pass"]))
    		$pass=$this->filter->injection_html($this->input->post('pass'));
	
    	if($ssid==$id)
    	{ 
    		$sessionLogin = array(
    				'sessionUserAdmin'  =>      'thang',
    				'sessionUser'      	=>      'thang'
    		);
    		$where="use_username = '$user'";
    		$sql="use_id, use_username, use_fullname, use_email, use_address, use_phone, use_yahoo, use_status, use_regisdate, use_enddate";
    		$userArray=$this->User_model->get($sql, $where);
    		if(count($userArray) != 1)
    		{
    			$md5=md5($ssid.rand());
    			$member = array('Login' => 'Sai thong tin TDN OR MK',
    					'pass' => 'xxxxxx',
    					'status'=>$md5);
    			$this->session->sess_destroy();//Huy session
    		}
    		else
    		{
    			$responce=array($userArray->use_id,$userArray->use_username,$userArray->use_fullname,$userArray->use_email,$userArray->use_address,$userArray->use_phone,$userArray->use_yahoo);
    			$md5=md5($ssid.'OK');
    			$member = array('Login' => 'Thanh cong',
    					'pass' => 'xxxxxx',
    					'status'=>$md5);
    			$this->session->set_userdata($sessionLogin);
    			$user_id      = $this->session->userdata('sessionUserAdmin');
    		}
    		echo json_encode($member);
    		
    	}
    	else
    	{
    		//$str = md5('12122121212121', 'md5')
			//$str=$this->hash->email_encode('ducthangs@gmail.com');
			//$str= hash('sha256', '12122121212121');
    		//echo $str;
			$this->load->view('admin/login/defaults');
    	}
    	
	}	
}